﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div id="carlist">
    <div>
        <input type="button" value="添加" onclick="caraddorupdateShow()" />
    </div>
    <div style="padding-top: 15px;">
        <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th class="th_short">
                        车辆牌号
                    </th>
                    <th class="th_short">
                        车辆名称
                    </th>
                    <th>
                    </th>
                </tr>
            </thead>
            <tbody>
                <%
                    System.Data.DataTable dt = ViewData["dt"] as System.Data.DataTable;
                    if (dt == null || dt.Rows.Count == 0)
                    {%>
                <tr>
                    <td colspan="0" style="text-align: center;">
                        当前无数据！
                    </td>
                </tr>
                <% }
                    else
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                %>
                <tr>
                    <td>
                        <%=dt.Rows[i]["车辆牌号"].ToString()%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["车辆名称"].ToString()%>
                    </td>
                    <td>
                        <a class="btn_detail" onclick="caraddorupdateShow('<%=dt.Rows[i]["车辆编码"]%>')">修改</a>
                    </td>
                </tr>
                <%
                    }
                    } %>
            </tbody>
        </table>
    </div>
</div>
<div id="caraddorupdate" style="display: none">
    <input type="hidden" id="car_id" />
    名称:<input type="text" id="car_name" /><br />
    车牌:<input type="text" id="car_number" />
    <input type="button" id="btn_submit" value="添加" onclick="docaraddorupdate()" />
    <input type="button" value="取消" onclick="caraddorupdateHide()" />
</div>

<script type="text/javascript">
    function caraddorupdateShow(car_id) {
        if (car_id != undefined && car_id != "") {
            $.ajax({
                type: "POST",
                url: "/Car/DoCarQuery",
                data: { "car_id": car_id },
                success: function(carEntity) {
                    if (carEntity != undefined && carEntity != null) {
                        $("#car_id").val(carEntity.car_id);
                        $("#car_name").val(carEntity.car_name);
                        $("#car_number").val(carEntity.car_number);
                        $("#btn_submit").val("保存");
                    }
                }
            })
        }
        else {
            $("#car_id").val("");
            $("#car_name").val("");
            $("#car_number").val("");
            $("#btn_submit").val("添加");
        }
        $("#caraddorupdate").show();
    }

    function caraddorupdateHide() {
        $("#caraddorupdate").hide();
    }

    function docaraddorupdate() {

        var car_id = $("#car_id").val();
        var car_name = $("#car_name").val();
        var car_number = $("#car_number").val();
        if (car_name == null || car_name == "") {
            alert("请输入车名");
            return;
        }
        if (car_number == null || car_number == "") {
            alert("请输入车牌");
            return;
        }
        $.ajax({
            type: "POST",
            url: "/Car/DoCarAddOrUpdate",
            data: { "car_id": car_id, "car_name": car_name, "car_number": car_number },
            success: function(restag) {
                if (restag.res) {
                    alert("操作成功");
                }
                else {
                    alert("操作失败");
                }
                $("#menu_carlist").trigger('click');
            }
        })
    }
</script>

